#！/usr/bin/env python
# coding=utf-8


def _find_links_in_str(data_str: str) -> list:
    ret = list()
    if not data_str:
        return ret
    # 去除换行符
    data_str = data_str.replace('\r', '')
    data_str = data_str.replace('\n', '')
    # 使用']('对字符串进行分割
    data_list = data_str.split("](")
    if len(data_list) == 1:
        return ret
    data_list = data_list[1:]
    for data in data_list:
        m = data.split(')')
        if m[0] not in ret:
            ret.append(m[0])
    return ret


def find_links_in_file(file_path: str) -> list:
    ret = list()
    try:
        with open(file_path, encoding='utf-8') as f:
            msg = f.read(-1)
            ret = _find_links_in_str(msg)
    except IOError:
        print(f"File IO err:{file_path}")

    return ret


if __name__ == "__main__":

    links = find_links_in_file('data.md')
    for link in links:
        print(link)

